layui.use(['layer', 'form', 'formX', 'setter', 'mynotice', 'admin', 'ax', 'util', 'dataGrid', 'element'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var formX = layui.formX;
    var setter = layui.setter;
    var mynotice = layui.mynotice;
    var admin = layui.admin;
    var $ax = layui.ax;
    var util = layui.util;
    var dataGrid = layui.dataGrid;
    var element = layui.element;
    
    var Buyinghouse = {
    	ins: {},
    	pattern: /^1(3|4|5|7|8)\d{9}$/,
    	dataGridRender:() => { // 渲染数据列表
    		Buyinghouse.ins = dataGrid.render({
    	        elem: '#wdList',  // 容器
    	        templet: '#itemlist',  // 模板
    	        url: '/zp/question/qlist',  // 数据接口
    	        page: {limit: 10},  // 开启分页
    	        done: function(res, curr, count){
    	        	
    	        }
    	    });
    		dataGrid.on('tool(wdList)', function (obj) {
                var modeldata = obj.data;
                if (obj.event === 'xtzx') {
                	admin.open({
            			type: 1,
            			title: false,
            			offset: 'auto',
            			closeBtn: 0,
            			skin: 'yourclass',
            			area: ['500px', '390px'],
            			content: $('#dialogform').html(),
            			success: function(layero, dIndex){
            				$(layero).children('.layui-layer-content').css('overflow', 'visible'); 
            				/*提交问题*/
            			    form.on('submit(questionsubmit)', function(data){
            			    	if(data.field.question == ''){
            			    		$("#queserro").removeClass('layui-hide');
            		            	return false;
            			    	}
            			    	if(data.field.phone != ''){
            			    		if(!Buyinghouse.pattern.test(data.field.phone)){
            		        			$("#erroMsg").removeClass('layui-hide');
            		            		return false;
            		        		}
            			    	}
            			    	layer.close(dIndex);
            			    	mynotice.load('提交中，请稍后...');
                			    var ajax = new $ax('/zp/question/add', 'post', function (res) {
                			    	mynotice.destroy();
                			    	admin.open({
                    	    			type: 1,
                    	    			title: false,
                    	    			offset: 'auto',
                    	    			closeBtn: 0,
                    	    			skin: 'yourclass',
                    	    			area: '500px',
                    	    			content: $('#dialogSuccessform').html(),
                    	    			success: function(layero, dIndex){
                    	    				$(layero).children('.layui-layer-content').css('overflow', 'visible'); 
                    	    			}
                    				})
                			    }, function (res) {
                			    	mynotice.destroy();
                			    	mynotice.error(res.msg);
                			    });
                			    data.field.consultant = modeldata.consultant;
                			    ajax.setData(JSON.stringify(data.field));
                			    ajax.start();
            				    return false;
            			    });
            			}
            		})
                }else if(obj.event === 'ckqw'){
					$(this).css("display", 'none');
					$(this).next().css("display", 'block');
					$(this).parent().prev().addClass("text-open");
					$(this).parent().prev().removeClass("text-close");
				}else if(obj.event === 'sq'){
					$(this).css("display", 'none');
					$(this).prev().css("display", 'block');
					$(this).parent().prev().addClass("text-close");
					$(this).parent().prev().removeClass("text-open");
				}
            });
    	}
    	
    }
    
    Buyinghouse.dataGridRender();
    
    //监听提交
    form.on('submit(searchformBtn)', function(data){
    	Buyinghouse.ins.reload({where: data.field}); 
    	return false;
    });
    
    util.event('lay-event', {
    	seac: function(){
    		if(!$(this).hasClass('on')){
    			var id = $(this).data('id');
    			$('.on').removeClass('on');
    			$(this).addClass('on');
    			Buyinghouse.ins.reload({where: {questionType: id} }); 
    		}
    		
    	}
    })
    
});